home *** CD-ROM | disk | FTP | other *** search
/ Gekkan Dennou Club 147 / Gekkan Dennou Club - 2000.8 Vol. 147 (Japan).7z / Gekkan Dennou Club - 2000.8 Vol. 147 (Japan) (Track 1).bin / docs / ippon / ver / 014 / ippon014.lzh / player.c < prev    next >
C/C++ Source or Header  |  2000-07-07  |  4KB  |  176 lines

  1. /* player.c */
  2.  
  3. #include <sys/iocs.h>
  4. #include <xsp2lib.h>
  5.  
  6. #include "main.h"
  7. #include "player.h"
  8. #include "shot.h"
  9.  
  10. #define PLAYER_BANK1    8    /* 少し傾きパターンへ移行するまでの値 */
  11. #define PLAYER_BANK2    12    /* 一番傾きパターンへ以下同文 */
  12.  
  13. #define PLAYER_SPEED    15    /* 自機の速度 */
  14. #define PLAYER_PALET    0x0700    /* 自機のパレット */
  15.  
  16. #define PLAYER_START_X    144    /* 自機出現時の座標 */
  17. #define PLAYER_START_Y    (256+32)
  18.  
  19.  
  20. enum {
  21.     PLAYER_PT_RIGHT2 = 0,    /* 自機が一番右に傾いている時のパターン */
  22.     PLAYER_PT_RIGHT1,    /*  〃 少し右に     〃      */
  23.     PLAYER_PT_CENTER,    /*  〃 正面を向いている時のパターン */
  24.     PLAYER_PT_LEFT1,    /* 自機が少し右に傾いている時のパターン */
  25.     PLAYER_PT_LEFT2        /*  〃 一番右に     〃      */
  26. };
  27.  
  28.  
  29.  
  30. /* ゲーム開始時に呼ばれる */
  31. void PlayerInit (void)
  32. {
  33. }
  34.  
  35.  
  36.  
  37. /* プレイヤー出現時に呼ばれる */
  38. void PlayerAlloc (void)
  39. {
  40.     player->lx = PLAYER_START_X * 65536;
  41.     player->ly = PLAYER_START_Y * 65536;
  42.     player->status = PLAYER_STATUS_APPEAR;    /* 出現状態へ */
  43. }
  44.  
  45.  
  46.  
  47. /* 自機が生きている時の移動処理 */
  48. static void PlayerMoveAlive (void)
  49. {
  50.     int j;            /* ジョイスティックの入力 */
  51.  
  52.     j = _iocs_joyget (0);    /* ジョイスティック0番 */
  53.  
  54.     /* [A] ボタンが押されたか? */
  55.     if ((j & 0b00100000) == 0)
  56.         game_over = !0;    /* ゲームオーバーに */
  57.  
  58.     /* [B] ボタンが押されたか? */
  59.     if ((j & 0b1000000) == 0)
  60.         ShotAlloc ();
  61.  
  62.     /* 自機の上下移動処理 */
  63.     switch (j & 0b0011) {
  64.     case 0b0010:        /* 上 */
  65.         player->ly += xytable[PLAYER_SPEED][192].y;
  66.         break;
  67.     case 0b0001:        /* 下 */
  68.         player->ly += xytable[PLAYER_SPEED][64].y;
  69.         break;
  70.     default:        /* それ以外 */
  71.         break;
  72.     }
  73.  
  74.     /* 自機の左右移動処理+左右傾き処理 */
  75.     switch (j & 0b1100) {
  76.     case 0b1000:        /* 左 */
  77.         player->lx += xytable[PLAYER_SPEED][128].x;
  78.         if (player->bank > 0) {
  79.             player->bank = 0;
  80.         } else {
  81.             if (player->bank > -PLAYER_BANK2)
  82.                 player->bank--;
  83.         }
  84.         break;
  85.  
  86.     case 0b0100:        /* 右 */
  87.         player->lx += xytable[PLAYER_SPEED][0].x;
  88.         if (player->bank < 0) {
  89.             player->bank = 0;
  90.         } else {
  91.             if (player->bank < PLAYER_BANK2)
  92.                 player->bank++;
  93.         }
  94.         break;
  95.  
  96.     default:        /* それ以外 */
  97.         /* 自機の傾きを元に戻す処理 */
  98.         if (player->bank != 0) {
  99.             if (player->bank > 0)
  100.                 player->bank--;
  101.             else
  102.                 player->bank++;
  103.         }
  104.         break;
  105.     }
  106.  
  107.     /* 自機の傾き (player->bank) から自機の複合スプライトNo.を求める */
  108.     if (player->bank == 0) {
  109.         player->pt = obj_player + PLAYER_PT_CENTER;
  110.     } else {
  111.         if (player->bank > 0) {
  112.             if (player->bank < PLAYER_BANK1)
  113.                 player->pt = obj_player + PLAYER_PT_LEFT1;
  114.             else
  115.                 player->pt = obj_player + PLAYER_PT_LEFT2;
  116.         } else {
  117.             if (player->bank > -PLAYER_BANK1)
  118.                 player->pt = obj_player + PLAYER_PT_RIGHT1;
  119.             else
  120.                 player->pt = obj_player + PLAYER_PT_RIGHT2;
  121.         }
  122.     }
  123.  
  124.     player->x = player->lx / 65536;
  125.     player->y = player->ly / 65536;
  126.  
  127.     xobj_set (player->x, player->y, player->pt, PLAYER_PALET | PRIORITY_PLAYER);    /* 自機を表示 */
  128. }
  129.  
  130.  
  131. /* 自機が死んだ時の移動処理 */
  132. static void PlayerMoveDead (void)
  133. {
  134.     /* 座標を初期化 */
  135.     player->lx = PLAYER_START_X * 65536;
  136.     player->ly = PLAYER_START_Y * 65536;
  137.     player->status = PLAYER_STATUS_APPEAR;    /* 出現状態へ */
  138. }
  139.  
  140.  
  141.  
  142. /* 自機が死んだ後の登場処理 */
  143. static void PlayerMoveAppear (void)
  144. {
  145.     player->bank = 0;
  146.     player->pt = obj_player + PLAYER_PT_CENTER;
  147.     player->ly -= (4 * 65536);
  148.  
  149.     player->x = player->lx / 65536;
  150.     player->y = player->ly / 65536;
  151.  
  152.     /* 自機がある程度上まで進んだら通常状態へ */
  153.     if (player->y < 160)
  154.         player->status = PLAYER_STATUS_ALIVE;
  155.  
  156.     xobj_set (player->x, player->y, player->pt, PLAYER_PALET | PRIORITY_PLAYER);    /* 自機を表示 */
  157. }
  158.  
  159.  
  160.  
  161. /* 垂直同期ごとに呼ばれる */
  162. void PlayerMove (void)
  163. {
  164.     switch (player->status) {
  165.     case PLAYER_STATUS_ALIVE:
  166.         PlayerMoveAlive ();
  167.         break;
  168.     case PLAYER_STATUS_DEAD:
  169.         PlayerMoveDead ();
  170.         break;
  171.     case PLAYER_STATUS_APPEAR:
  172.         PlayerMoveAppear ();
  173.         break;
  174.     }
  175. }
  176.